package com.mybatis.panel;

import com.mybatis.entity.AwardPunish;
import com.mybatis.entity.Sstatus;
import com.mybatis.service.AwardPunishService;
import com.mybatis.service.SstatusService;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class SstatusInsertPanel extends JPanel {

    public static int pageSize = 1;

    public static String dataRow;

    public SstatusInsertPanel() {
        setLayout(null);
        setBounds(0, 0, 300, 300);

        //===========================================
//        JPanel panel = new JPanel(new BorderLayout());
//        panel.setBounds(0, 0, 900, 600);//位置
//        panel.add(new JLabel("用户名"));//文字


        JPanel panel2 = new JPanel();
        panel2.setBounds(0, 140, 0, 0);
        add(panel2);

        JLabel jLabel3 = new JLabel();
        jLabel3.setText("学号:");
        jLabel3.setBounds(55, 10, 50, 50);
        add(jLabel3);

        JLabel jLabel4 = new JLabel();
        jLabel4.setBounds(30, 35, 70, 50);
        jLabel4.setText("学籍有无:");
        add(jLabel4);

        JLabel jLabel5 = new JLabel();
        jLabel5.setBounds(30, 60, 70, 50);
        jLabel5.setText("入学日期:");
        add(jLabel5);

        JLabel jLabel6 = new JLabel();
        jLabel6.setBounds(30, 85, 70, 50);
        jLabel6.setText("毕业日期:");
        add(jLabel6);

        JLabel jLabel7 = new JLabel();
        jLabel7.setBounds(58, 110, 70, 50);
        jLabel7.setText("类别:");
        add(jLabel7);

        JLabel jLabel8 = new JLabel();
        jLabel8.setBounds(58, 130, 70, 50);
        jLabel8.setText("学制:");
        add(jLabel8);


        //文本框
        JTextField jTextField1 = new JTextField(10);
        jTextField1.setBounds(100, 25, 100, 20);
        add(jTextField1);

        //add(jLabel4);

        JTextField jTextField2 = new JTextField(10);
        jTextField2.setBounds(100, 50, 100, 20);
        add(jTextField2);

        JTextField jTextField3 = new JTextField(10);
        jTextField3.setBounds(100, 75, 100, 20);
        add(jTextField3);

        JTextField jTextField4 = new JTextField(10);
        jTextField4.setBounds(100, 100, 100, 20);
        add(jTextField4);

        JTextField jTextField5 = new JTextField(10);
        jTextField5.setBounds(100, 125, 100, 20);
        add(jTextField5);

        JTextField jTextField6 = new JTextField(10);
        jTextField6.setBounds(100, 150, 100, 20);
        add(jTextField6);



        JButton loginButton = new JButton("添加");
        //loginButton.setText("www");
        loginButton.setBounds(70, 200, 40, 30);
        loginButton.setMargin(new Insets(0, 0, 0, 0));
        add(loginButton, BorderLayout.WEST);

        final int[] type = {0};



        loginButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {

                String text1 = jTextField1.getText();
                String text2 = jTextField2.getText();
                String text3 = jTextField3.getText();
                String text4 = jTextField4.getText();
                String text5 = jTextField5.getText();
                String text6 = jTextField6.getText();
//                if (text == null || text.length() <= 0 || password == null || password.length() <= 0) {
//                    JOptionPane.showMessageDialog(panel2,
//                            "用户名或密码不能为空", "系统提示", JOptionPane.WARNING_MESSAGE);
//                    return;
//                }
                Sstatus sstatus = new Sstatus();
                sstatus.setSno(text1);
                sstatus.setSstatu(text2);
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                LocalDate date = LocalDate.parse(text3, formatter);
                sstatus.setEtime(date);
                LocalDate date2 = LocalDate.parse(text3, formatter);
                sstatus.setGtime(date2);
                sstatus.setStype(text5);
                sstatus.setXuezhi(Integer.parseInt(text6));


                Sstatus one1 = SstatusService.getOne(sstatus);

                if (one1!=null){
                    JOptionPane.showMessageDialog(panel2,
                            "记录已存在", "系统提示", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                SstatusService.insert(sstatus);
                JOptionPane.showMessageDialog(panel2,
                        "添加成功", "系统提示", JOptionPane.WARNING_MESSAGE);
                return;
            }
        });


//        jButton.addMouseListener(new MouseAdapter() {
//            @Override
//            public void mouseClicked(MouseEvent e) {
//                String text = jTextField.getText();
//                char[] password = passwordField.getPassword();
//                if (text == null || text.length() <= 0 || password == null || password.length <= 0) {
//                    JOptionPane.showMessageDialog(panel2,
//                            "用户名或密码不能为空", "系统提示", JOptionPane.WARNING_MESSAGE);
//                    return;
//                }
//                User user = new User();
//                user.setName(text);
//                user.setPassword(String.valueOf(password));
//                Integer integer = UserService.getAll();
//                user.setId(++integer);
//                //System.out.println(user);
//                user.setType(type[0]);
//                User aNull = UserService.getNull(user);
//                if (aNull != null) {
//                    JOptionPane.showMessageDialog(panel2,
//                            "用户名已存在!", "系统提示", JOptionPane.WARNING_MESSAGE);
//                    return;
//                }
//                UserService.insert(user);
//                JOptionPane.showMessageDialog(panel2,
//                        "注册成功", "系统提示", JOptionPane.WARNING_MESSAGE);
//                //setPanel(new StudentPanel());
//            }
//        });

    }

    public void setPanel(int page) {
        pageSize = page;
        MainJFrame.setPanel(new SstatusInsertPanel());
    }

    public void setPanel(JPanel panel) {
        MainJFrame.setPanel(panel);
    }

}
